package com.moss.cloud.base.biz.controller;

import com.moss.cloud.base.api.model.from.BaseFrom;
import com.moss.cloud.base.api.model.from.FlowModelFrom;
import com.moss.cloud.base.api.model.param.FlowModelParam;
import com.moss.cloud.base.biz.service.IFlowModelService;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 流程模型前端控制器
 *
 * @author 瑾年
 * @date 2024-02-06
 */
@RestController
@RequestMapping(ServiceList.BASE + "/flowModel")
public class FlowModelController {

    private final IFlowModelService flowModelService;

    public FlowModelController(IFlowModelService flowModelService) {
        this.flowModelService = flowModelService;
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @PostMapping("/page")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "分页查询")
    public Result<?> page(@RequestBody @Validated FlowModelParam param) {
        return Result.success(flowModelService.page(param));
    }

    /**
     * 流程模型列表
     *
     * @param param
     * @return
     */
    @PostMapping("/list")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "流程模型列表")
    public Result<?> list(@RequestBody @Validated FlowModelParam param) {
        return Result.success(flowModelService.flowModelList(param));
    }

    /**
     * 新增
     *
     * @param from
     * @return
     */
    @PostMapping("/save")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "新增流程模型")
    public Result<?> saveFlowModel(@RequestBody @Validated FlowModelFrom from) {
        return Result.success(flowModelService.saveFlowModel(from));
    }

    /**
     * 更新
     *
     * @param from
     * @return
     */
    @PostMapping("/update")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "更新流程模型")
    public Result<?> update(@RequestBody @Validated FlowModelFrom from) {
        return Result.success(flowModelService.update(from));
    }

    /**
     * 删除
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/remove")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "删除流程模型")
    public Result<?> remove(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(flowModelService.remove(baseFrom));
    }

    /**
     * 详情
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/detail")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "流程模型详情")
    public Result<?> detail(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(flowModelService.detail(baseFrom));
    }


}
